# 1.requests 发送请求 从服务器获取数据
# 2.BeautifulSoup 解析整个页面的源代码

import requests
from bs4 import BeautifulSoup

# 发送请求到服务器

# def print_hi(name):
#     # Use a breakpoint in the code line below to debug your script.
#     print(f'Hi, {name}')  # Press Ctrl+F8 to toggle the breakpoint.


# resp = requests.get("https://www.sina.com.cn/")  # 从服务器拿到源码
resp = requests.get("http://www.umei.cc/meinvtupian/meinvxiezhen/")
resp.encoding = 'utf-8'
# print(resp.text)

# 解析html
main_page = BeautifulSoup(resp.text, "html.parser")
# 从页面中找到某些东西
# find() 找一个
# find_all() 找所有
alst = main_page.find("div", attrs={"class": "pic-box"}).find_all("a", attrs={"class": "loaded"})
print(alst)

for a in alst:
    href = a.get("href")  # http://www.beian.gov.cn/portal/registerSystemInfo?recordcode=11000002000016
    # 发送请求到子页面
    resp1 = requests.get(href)
    resp1.encoding = 'utf-8'
    child_page = BeautifulSoup(resp1.text, "html.parser")
    # 找到图片的真实路径
    src = child_page.find("div", attrs={"class": "ImageBody"}).find("img").get("src")
    print(src)

# print(aLst)


# Press the green button in the gutter to run the script.
# if __name__ == '__main__':
#     print_hi('PyCharm')

# See PyCharm help at https://www.jetbrains.com/help/pycharm/
